package com.ricchieri.task;

import java.net.URL;

import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.ricchieri.bean.AntProcessBean;
import com.ricchieri.common.AntProcess;
import com.ricchieri.common.BusinessSettings;
import com.ricchieri.exception.AntException;

@Service
public class DatabaseTask {
	
    @Scheduled(fixedRate = 86400000)
    public void createBackup() {

    	AntProcess process = new AntProcess();
    	AntProcessBean processBean = new AntProcessBean();
    	processBean.setTarget(BusinessSettings.ANT_TARGET_CREATE_BACKUP);
    	
    	URL absoluteDiskPath = getClass().getResource(BusinessSettings.ANT_DATABASE_FILE);
    	processBean.setFile(absoluteDiskPath.getPath());
    	
		try {
			process.executeProcess(processBean);
		} catch (AntException e) {
			e.printStackTrace();
		}
    }
 
}
